package com.formulas.component.extension;

/**
 * 扩展坐标用于唯一的定位扩展
 * @author yiwannuofulasi
 * @date 2023/6/12 16:42
 */
public class ExtensionCoordinate {

    /**扩展点名称**/
    private String extensionPointName;
    /**业务场景唯一标识**/
    private String bizScenarioUniqueIdentity;
    /**扩展点类包装器**/
    private Class extensionPointClass;
    /**业务场景**/
    private BizScenario bizScenario;

    /**
     * 获取扩展点类包装器
     * @return Class
     */
    public Class getExtensionPointClass() {
        return extensionPointClass;
    }

    /**
     * 获取业务场景
     * @return BizScenario
     */
    public BizScenario getBizScenario() {
        return bizScenario;
    }

    /**
     * 扩展协调转换
     * @param extPtClass 扩展点类包装器
     * @param bizScenario 业务场景
     * @return ExtensionCoordinate
     */
    public static ExtensionCoordinate valueOf(Class extPtClass, BizScenario bizScenario){
        return new ExtensionCoordinate(extPtClass, bizScenario);
    }

    /**
     * 扩展协调构造器
     * @param extPtClass 扩展点类包装器
     * @param bizScenario 业务场景
     */
    public ExtensionCoordinate(Class extPtClass, BizScenario bizScenario){
        this.extensionPointClass = extPtClass;
        this.extensionPointName = extPtClass.getName();
        this.bizScenario = bizScenario;
        this.bizScenarioUniqueIdentity = bizScenario.getUniqueIdentity();
    }

    /**
     * 扩展协调构造器
     * @param extensionPoint 扩展点名称
     * @param bizScenario 业务场景唯一标识码
     */
    public ExtensionCoordinate(String extensionPoint, String bizScenario){
        this.extensionPointName = extensionPoint;
        this.bizScenarioUniqueIdentity = bizScenario;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((bizScenarioUniqueIdentity == null) ? 0 : bizScenarioUniqueIdentity.hashCode());
        result = prime * result + ((extensionPointName == null) ? 0 : extensionPointName.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        ExtensionCoordinate other = (ExtensionCoordinate) obj;
        if (bizScenarioUniqueIdentity == null) {
            if (other.bizScenarioUniqueIdentity != null) return false;
        } else if (!bizScenarioUniqueIdentity.equals(other.bizScenarioUniqueIdentity)) return false;
        if (extensionPointName == null) {
            if (other.extensionPointName != null) return false;
        } else if (!extensionPointName.equals(other.extensionPointName)) return false;
        return true;
    }

    @Override
    public String toString() {
        return "ExtensionCoordinate [extensionPointName=" + extensionPointName + ", bizScenarioUniqueIdentity=" + bizScenarioUniqueIdentity + "]";
    }
}
